﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.Admin
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        private DataClassesHeaxlthDataContext dc = new DataClassesHeaxlthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AdminLogin ad = (AdminLogin)Session["admin"];
                if (ad == null)
                {
                    Response.Redirect("login.aspx");
                }
                else
                {
                    if (ad.pemision == 2)
                    {
                        Response.Redirect("login.aspx");
                    }
                    else
                    {
                        this.Repeater1.DataSource = this.dc.EmpRegisters.ToList().OrderByDescending(a => a.empno);
                        this.Repeater1.DataBind();
                    }
                }
            }
        }
        protected void LinkButtonXoa_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lb = (LinkButton)sender;
                HiddenField hd = (HiddenField)lb.Parent.FindControl("HiddenFieldEmpno");
                
                EmpRegister emp = this.dc.EmpRegisters.Single(a=> a.empno == Convert.ToInt32(hd.Value));

                this.dc.EmpRegisters.DeleteOnSubmit(emp);
                this.dc.SubmitChanges();



                this.Repeater1.DataSource = this.dc.EmpRegisters.ToList();
                this.Repeater1.DataBind();

                this.mesage_success.Visible = true;
                this.message_error.Visible = false;

            }
            catch
            {
                this.message_error.Visible = true;
                this.mesage_success.Visible = false;
            }
        }
            protected void LinkButton1_Click(object sender, EventArgs e)
            {
                mesage_success.Visible = false;
            }
    }
}